home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianJpeg.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  172 lines

  1. /*ScianJpeg.c
  2.   Robert Sumner 
  3.   August 17, 1993 
  4.   Jpeg pseudorecorder*/
  5.  
  6. #include "Scian.h"
  7. #include "ScianTypes.h"
  8. #include "ScianWindows.h"
  9. #include "ScianIDs.h"
  10. #include "ScianJpeg.h"
  11. #include "ScianRecorders.h"
  12.  
  13. #ifdef JPEGRECORDER
  14.  
  15. static long curJpegFrame = 0;
  16.  
  17. static ObjPtr ReturnTrue(object)
  18. ObjPtr object;
  19. /*Returns true*/
  20. {
  21.     return ObjTrue;
  22. }
  23.  
  24. static ObjPtr PrepareToRecordJpeg(object, nFrames)
  25. ObjPtr object;
  26. long nFrames;
  27. /*Prepares to record nframes*/
  28. {
  29.     curJpegFrame = 0;
  30.     return ObjTrue;
  31. }
  32.  
  33. static ObjPtr SnapOneFrameJpeg(object)
  34. ObjPtr object;
  35. /*Do a screen dump of arbitrary size*/
  36. {
  37.     int l, b, r, t,  w, h;
  38.     ObjPtr var;
  39.     unsigned long int *JpegArray;
  40.  
  41.     fullscrn();
  42.  
  43.  
  44.     SetOrigin(0,0);
  45.     
  46.     var = GetVar(object, FRAMEOX);
  47.     if (var)
  48.     {
  49.         l = GetInt(var);
  50.     }
  51.     else
  52.     {
  53.         l = 0;
  54.     }
  55.  
  56.     var = GetVar(object, FRAMEOY);
  57.     if (var)
  58.     {
  59.         b = GetInt(var);
  60.     }
  61.     else
  62.     {
  63.         b = 0;
  64.     }
  65.  
  66.  
  67.     var = GetVar(object, FRAMEWIDTH);
  68.     if (var)
  69.     {
  70.     w = GetInt(var);
  71.     }
  72.     else
  73.     {
  74.     w = 0;
  75.     }
  76.  
  77.     var = GetVar(object, FRAMEHEIGHT);
  78.     if (var)
  79.     {
  80.     h = GetInt(var);
  81.     }
  82.     else
  83.     {
  84.     h = 0;
  85.     }
  86.     
  87.     r = l + w - 1;
  88.     t = b + h - 1;
  89.  
  90.     if (GetPredicate(object, SAVEWINDOWFRAME))
  91.     {
  92.                 l -= WINBL;
  93.                 r += WINBR;
  94.                 b -= WINBB;
  95.                 t += WINBT;
  96.     }
  97.  
  98.  
  99.     /* advance to the next frame in the directory */
  100.     do
  101.     {
  102.     ++curJpegFrame;
  103.     sprintf(tempStr, "screen%04d.jpg", curJpegFrame);
  104.     } while (fopen(tempStr, "r"));
  105.  
  106.     SetVar(object, FILENAME, NewString(tempStr));
  107.  
  108.  /* Store the name of the current frame in *tempStr */
  109.     sprintf(tempStr, "screen%04d.jpg", curJpegFrame);
  110.  
  111.  /* Allocate the memory for the dynamic array */    
  112.     JpegArray = (unsigned long int *) Alloc(sizeof(unsigned long int) * (w)  * (h) );
  113.  
  114.  /* Check to make sure an address was returned */ 
  115.     if (!JpegArray)
  116.     {
  117.     printf("Insufficient memory to save image.\n");
  118.         return ObjFalse;
  119.     }  
  120.  
  121.  /* Change to full screen mode */
  122. /*    fullscrn();
  123. */
  124.  /* Read the pixels into the array */ 
  125.     lrectread(l, b, r, t, JpegArray);
  126.  
  127.  /* Save the array to *tempStr */
  128.     printf("Saving frame %04d to 'screen%04d.jpg'\n",curJpegFrame,curJpegFrame); 
  129.     printf("l=%04d     b=%04d    r=%04d    t=%04d\n",l,b,r,t);
  130.     printf("jpaste screen%04d.jpg\n\n",curJpegFrame);
  131.     SaveJPEGImagePtr(tempStr, JpegArray, (w), (h));
  132.  
  133.  /* Change out of full screen mode */
  134.     endfullscrn();
  135.     RestoreOrigin();
  136.  
  137.  /* Free the memory */
  138.     SAFEFREE(JpegArray);
  139.  
  140. return ObjTrue;
  141. }
  142.  
  143. #ifdef PROTO
  144. void InitJpeg(void)
  145. #else
  146. void InitJpeg()
  147. #endif
  148. /*Create a new screen dump ersatz recorder*/
  149. {
  150.     ObjPtr recorder;
  151.  
  152.     recorder = NewRecorder(NULLOBJ, "JPEG", "Compressed JPEG");
  153.     SetMethod(recorder, CONNECT, ReturnTrue);
  154.     SetMethod(recorder, DISCONNECT, ReturnTrue);
  155.     SetMethod(recorder, PREPARETORECORD, PrepareToRecordJpeg);
  156.     SetMethod(recorder, STOPRECORDING, ReturnTrue);
  157.     SetMethod(recorder, SNAPONEFRAME, SnapOneFrameJpeg);
  158.     SetVar(recorder, FRAMESOURCE, NewInt(FS_WINDOW));
  159.     SetVar(recorder, ENABLEDSOURCES, NewInt(FB_SCREEN + FB_WINDOW));
  160.     RegisterRecorder(recorder);
  161. }
  162.  
  163. #ifdef PROTO
  164. void KillJpeg(void)
  165. #else
  166. void KillJpeg()
  167. #endif
  168. {
  169. }
  170.  
  171. #endif
  172.